/*============================================================================*/
/*                    CONTINENTAL AUTOMOTIVE SYSTEMS                          */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* %name:            stdtypedef.h%
* %version:         1.0%
* %created_by:      David Robles%
* %date_created:    December 08 2012%
*=============================================================================*/
/* DESCRIPTION : Platform software type definitions                           */
/*============================================================================*/
/* FUNCTION COMMENT :                                                         */
/*                                                                            */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1        | 08/12/2012  |                               |David Robles      */
/* Created file                                                               */
/*----------------------------------------------------------------------------*/

#ifndef STDTYPEDEF_H
#define STDTYPEDEF_H


/* Define datatype length according to the ECU */
typedef unsigned char      T_UBYTE;
typedef unsigned short int T_UWORD;
typedef unsigned long int  T_ULONG;
typedef signed char        T_SBYTE;
typedef signed short int   T_SWORD;
typedef signed long int    T_SLONG;
typedef unsigned char      T_UFLAG;


/* Basic type pointers */
typedef T_UBYTE * PTR_UBYTE ;
typedef T_UWORD * PTR_UWORD;
typedef T_ULONG * PTR_ULONG;
typedef T_SBYTE * PTR_SBYTE ;
typedef T_SWORD * PTR_SWORD;
typedef T_SLONG * PTR_SLONG;


/* Carrier of 8 bits */
typedef struct
{
	T_UBYTE bit0 : 1;
	T_UBYTE bit1 : 1;
	T_UBYTE bit2 : 1;
	T_UBYTE bit3 : 1;
	T_UBYTE bit4 : 1;
	T_UBYTE bit5 : 1;
	T_UBYTE bit6 : 1;
	T_UBYTE bit7 : 1;
} T_BITFIELD8;


/* Carrier of 16 bits */
typedef struct
{
	T_UBYTE bit_0 : 1;
	T_UBYTE bit_1 : 1;
	T_UBYTE bit_2 : 1;
	T_UBYTE bit_3 : 1;
	T_UBYTE bit_4 : 1;
	T_UBYTE bit_5 : 1;
	T_UBYTE bit_6 : 1;
	T_UBYTE bit_7 : 1;
	T_UBYTE bit_8 : 1;
	T_UBYTE bit_9 : 1;
	T_UBYTE bit_10 : 1;
	T_UBYTE bit_11 : 1;
	T_UBYTE bit_12 : 1;
	T_UBYTE bit_13 : 1;
	T_UBYTE bit_14 : 1;
	T_UBYTE bit_15 : 1;
} T_BITFIELD16;


/* Carrier of 32 bits */
typedef struct
{
	T_UBYTE bit_0 : 1;
	T_UBYTE bit_1 : 1;
	T_UBYTE bit_2 : 1;
	T_UBYTE bit_3 : 1;
	T_UBYTE bit_4 : 1;
	T_UBYTE bit_5 : 1;
	T_UBYTE bit_6 : 1;
	T_UBYTE bit_7 : 1;
	T_UBYTE bit_8 : 1;
	T_UBYTE bit_9 : 1;
	T_UBYTE bit_10 : 1;
	T_UBYTE bit_11 : 1;
	T_UBYTE bit_12 : 1;
	T_UBYTE bit_13 : 1;
	T_UBYTE bit_14 : 1;
	T_UBYTE bit_15 : 1;
	T_UBYTE bit_16 : 1;
	T_UBYTE bit_17 : 1;
	T_UBYTE bit_18 : 1;
	T_UBYTE bit_19 : 1;
	T_UBYTE bit_20 : 1;
	T_UBYTE bit_21 : 1;
	T_UBYTE bit_22 : 1;
	T_UBYTE bit_23 : 1;
	T_UBYTE bit_24 : 1;
	T_UBYTE bit_25 : 1;
	T_UBYTE bit_26 : 1;
	T_UBYTE bit_27 : 1;
	T_UBYTE bit_28 : 1;
	T_UBYTE bit_29 : 1;
	T_UBYTE bit_30 : 1;
	T_UBYTE bit_31 : 1;
} T_BITFIELD32;


/* Word with msb and lsb handling */
typedef union{
  T_UWORD   wo;
  struct{
    T_UBYTE msb;
    T_UBYTE lsb;
  }by;
}T_BYTEFLD;


/* Long with word and byte handling */
typedef union{
  T_ULONG lo;
  struct {
    T_UBYTE highword_msb;
    T_UBYTE highword_lsb;
    T_UBYTE lowword_msb;
    T_UBYTE lowword_lsb;
  } by;
  struct {
    T_UWORD highword;
    T_UWORD lowword;
  } wo;
}T_BYTEFLD32;


/* Carrier of 8 bits with byte handling */
typedef union {
    T_UBYTE by;
    T_BITFIELD8   bi;
}T_FLAG8;


/* Carrier of 16 bits with word or byte (msb & lsb) carrier handling */
typedef union {
    T_BYTEFLD cr;
    T_BITFIELD16 bi;
}T_FLAG16;


/* Carrier of 32 bits with word or byte (msb & lsb) carrier handling */
typedef union {
    T_BYTEFLD32 cr;
    T_BITFIELD32  bi;
}T_FLAG32;

/* New data types */
typedef enum
{
	BTRUE,
	BFALSE
} E_BOOLEAN;

typedef enum
{
    FALSE = 0,
    TRUE  = 1
}TYPE_BOOLEAN;

/* Macros definition */
#define _MAX_UBYTE_		0xFF
#define _MAX_UWORD_		0xFFFF
#define _MAX_ULONG_		0xFFFFFFFF
#define _MIN_UBYTE_		0x00
#define _MIN_UWORD_		0x0000
#define _MIN_ULONG_		0x00000000
/* TODO
#define _MAX_SBYTE_		
#define _MAX_SWORD_		
#define _MAX_SLONG_		
#define _MIN_SBYTE_		
#define _MIN_SWORD_		
#define _MIN_SLONG_		
*/

/* Compiler customization */
/* Memory macros definition */
#define IRAM                            /* RAM declaration into internal RAM */
#define NEAR                            /* RAM declaration into near RAM */
#define FAR                             /* RAM declaration into far RAM */
#define PRIVATE_DATA static             /* static data definition */
#define PRIVATE_FCT static              /* private function definition */
#define PUBLIC_DATA extern              /* extern data definition */
#define PUBLIC_FCT extern               /* extern function definition */
#define NEAR_FCT                        /* near function definition */
#define FAR_FCT                         /* far function definition */
#define INLINE_FCT                      /* inline function definition */

/* Common macros definition, just if they are missing from above*/
#ifndef TRUE
#define TRUE  (1u)
#endif

#ifndef FALSE
#define FALSE (0u)
#endif

#ifndef HIGH
#define HIGH  (1u)
#endif

#ifndef LOW
#define LOW   (0u)
#endif

#ifndef NULL
#define NULL  (0u)
#endif


#endif  /* #ifndef STDTYPEDEF_H   #define STDTYPEDEF_H */